package com.fz.controller;

import com.fz.entity.Book;
import com.fz.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by webrx on 2017-07-07.
 */
@Controller
public class BookController {
    @Autowired
    private BookMapper bookdao;

    @RequestMapping("/index")
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView("index");
        mv.addObject("books",bookdao.query());
        return mv;
    }

    @RequestMapping("/del")
    public String del(int id){
        bookdao.delById(id);
        return "redirect:/index";
    }

    @RequestMapping("/add")
    public String add(){
        return "add";
    }

    @RequestMapping("/save")
    public String save(Book book){
        bookdao.save(book);
        return "redirect:/index";
    }
}
